<html>
<head>
<?php
require_once dirname(__FILE__) . '/data.inc.php';
$payment_id = $_GET["pay_pid"];
$data = getData($payment_id, 0);
$link = '?i=';
?>
<link href="ecommerce/payments/<?php echo $folder; ?>/assets/default.css" rel="stylesheet" type="text/css" />
<style>
.table td {
  height: 30px;
}
.left_td {
  font-weight: bold;
  text-align: right;
  padding: 2px 10px 2px 20px;
  margin-right: 20px;
  background-color: #d6e3e8;
  font-family: Trebuchet MS;
  width: 150px;
  height: 30px;
}
._text {
  width: 200px;
  height: 26px;
}
._select {
  width: 200px;
  height: 26px;
}
</style>
<script type="text/javascript" src="libs/json/json2.js"></script>
<script type="text/javascript" src="libs/jquery/jquery-1.6.2.min.js"></script>
<script>
function submit() {
  var w = document.getElementById('width');
  var h = document.getElementById('height');
  var f = document.getElementById('formal');
  var a = document.getElementById('account');
  var cc = document.getElementById('currency_code');
  var r = document.getElementById('return_link');
  var c = document.getElementById('cancel_link');

  var obj = {
    id: '<?php echo $payment_id; ?>',
    width: w.value,
    height: h.value,
    is_formal: f.checked ? 1 : 0,
    account: a.value,
    currency_code: ((cc.options.length > 0) ? cc.options[cc.selectedIndex].value : ''),
    return_link: ((r.options.length > 0) ? '<?php echo $link; ?>' + r.options[r.selectedIndex]._obj.id : ''),
    cancel_link: ((c.options.length > 0) ? '<?php echo $link; ?>' + c.options[c.selectedIndex]._obj.id : '')
  };
  $.ajax({
    type: "POST",
    url: "ecommerce/payments/<?php echo $folder; ?>/server.php",
    data: "action=submit&q=" + JSON.stringify(obj),
    success: function(msg) {
      try {
        JSON.parse(msg);
        location.reload();
      } catch (ex) {
        alert( "Error: " + msg);
      }
    }
  });
}
//-->
</script>
</head>

<body height="100px">
<table width="100%" height="100px">
  <tr>
    <td class="left_td">Width</td>
    <td><input id="width" class="_text" style="margin-left: 4px;"  type="text" value=<?php echo $data->width; ?>></input></td>
  </tr>
  <tr>
    <td class="left_td">Height</td>
    <td><input id="height" class="_text" style="margin-left: 4px;"  type="text" value=<?php echo $data->height; ?>></input></td>
  </tr>
  <tr>
    <td class="left_td">Is Formal</td>
    <td><input id="formal" type="checkbox" <?php if ($data->payment->is_formal == 1) echo 'checked="checked"'; ?>></input></td>
  </tr>
  <tr>
    <td class="left_td">Account</td>
    <td><input id="account" class="_text" style="margin-left: 4px;"  type="text" value=<?php echo $data->payment->account; ?>></input></td>
  </tr>
  <tr>
    <td class="left_td">Currency Payment</td>
    <td><select id="currency_code" class="_select" style="margin-left: 4px;" >
    <?php
    foreach ($data->codes as $tmp) {
      echo '<option value=' . $tmp . ((count($data->codes) > 0 && $tmp == $data->payment->currency_code) ? ' selected=\"selected\"' : '') . '>' . $tmp . '</option>';
    }
    ?>
    </select></td>
  </tr>
  <tr>
    <td class="left_td">Return Page</td>
    <td>
      <select id="return_link" class="_select" style="margin-left: 4px;" ></select><span>
    </td>
  </tr>
  <tr>
    <td class="left_td">Cancel Page</td>
    <td>
      <select id="cancel_link" class="_select" style="margin-left: 4px;" ></select>
    </td>
  </tr>
  <tr>
    <td></td>
    <td>
      <span class="image_button" style="width: 75px; margin-left: 4px; margin-top: 5px" onclick="submit();">
        <table>
          <tr>
            <td><img src="ecommerce/payments/<?php echo $folder; ?>/assets/save.png"></img></td>
            <td>Save</td>
          </tr>
        </table>
      </span>
    </td>
  </tr>
</table>
<script>
<!--
  if (document.addEventListener) {
    document.addEventListener('DOMContentLoaded', init, false);
  }
  window.onload = init;

  var r = document.getElementById('return_link');
  var c = document.getElementById('cancel_link');
   _menus = JSON.parse('<?php echo addslashes(json_encode($data->menus)); ?>');
  
  function init() {
    if (!document.getElementById || !document.createElement || !arguments || arguments.callee._loaded) {
      return;
    }
    arguments.callee._loaded = true;

    setParent(r, _menus, 0, '<?php echo $data->payment->return_link; ?>');
    setParent(c, _menus, 0, '<?php echo $data->payment->cancel_link; ?>');
  }

  function setParent(select, node, level, link) {
    if (node.name == 'ROOT') {
      node.name = '-';
    }
    
    op = new Option(node.name);
    op._obj = node;
    op.style.paddingLeft = level * 5 + 'px';
    
    if (link == '<?php echo $link; ?>' + node.id) {
      op.selected = 'selected';
    }
    select.options[select.options.length] = op;
    
    for (var i = 0, il = node.c.length; i < il; i++) {
      setParent(select, node.c[i], level + 1, link);
    }
  }
</script>
</body>
</html>
